import type { SysDepartment } from "@/entity/SysDepartment";
import { BaseEntityService } from "./base-entity.service";
import httpClient from "./http-client";
import type { AxiosResponse } from "axios";
import type { ResponseResult } from "@/entity/ResponseResult";

export class SysDepartmentService extends BaseEntityService<SysDepartment> {
    baseUrl = "/api/v1.0/admin/department";

    async treeList() {
        return httpClient.post(`${this.baseUrl}/tree-list`).then((res: AxiosResponse<ResponseResult<SysDepartment[]>>) => {
            if (res.data.data) {
                const tree = res.data.data;
                return Promise.resolve(tree);
            } else {
                throw "no data";
            }
        });
    }
}

const departmentService = new SysDepartmentService();

export default departmentService;